<!--
	Carnegie Mellon University
	School of Computer Science
	MSIT eBusiness Technology

	Team 8 - Infinity (2011 Spring)
	infinity-team8@googlegroups.com

	Professor: Jeffrey L. Eppinger
	Program Faculty: Sujata Telang
-->

<jsp:include page="customer-template-top.jsp" />
<jsp:include page="customer-topnav.jsp" />
<div id="header"><h1>Sell Fund</h1></div>

<%@ page import="databean.PositionBean" %>
<%@ page import="model.CustomerDAO" %>
<%@ page import="model.PositionDAO" %>
<%@ page import="model.FundDAO" %>
<%@ page import="databean.CustomerBean" %>
<jsp:include page="customer-sidebar.jsp" />

<div id="content">
	<div id="form-wrapper">
		<jsp:include page="customer-error-list.jsp" />	
			<form method="post" action="customer-sell-fund.do">			
				<div class="line-wrap">
				<label>Fund Symbol  </label>
				<div class="field"><select style="margin-left:-250px" name="fundID">
						<%
							PositionBean[] positions = (PositionBean[]) request.getAttribute("positionList");
							CustomerBean customer = (CustomerBean) session.getAttribute("customer");
							PositionDAO positionDAO = new PositionDAO();
							FundDAO fundDAO = new FundDAO();
							
							boolean hasShares = true;
							
							if (positions==null) {
								hasShares = false;
						%>
								<option value="">No available shares for selling</option>
						<%
							} else {
								for (PositionBean position : positions) {
						%>
								<option value="<%=position.getFundID()%>"><%=fundDAO.lookup(position.getFundID()).getSymbol()%> (available shares: <%=positionDAO.getAvailableSharesFormatted(customer.getCustomerID(), position.getFundID())%>)</option>
						<%
								}
							}
						%>
					</select></div></div>
				<div class="line-wrap">
				<label>Shares  </label>
				<div class="field"><input class="medium" style="margin-left:-250px" type="text" name="shares" value=""/>
				</div>
				</div>
				<div class="button">
				<%
					if (hasShares) {
				%>
						<input type="submit" name="button" value="Sell"/>
				<%
					} else {
				%>
						<input type="submit" name="button" value="No available shares!" disabled/>
				<%
					}
				%>
				</div>	
			</form>
	</div>
</div>


<jsp:include page="footer.jsp" />
